﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;

namespace BLL
{
    public class SendMail
    {
        #region Constructor

        public SendMail()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        #endregion Constructor

        #region Variables

        private static readonly SmtpClient _client = new SmtpClient(SMTP_SERVER);

        #endregion Variables

        #region Properties

        private static string SMTP_SERVER
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["SMTP_SERVER"];
            }
        }

        private static string ADMIN_EMAIL_FROM
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["ADMIN_EMAIL_FROM"];
            }
        }

        public static string ADMIN_EMAILS_CC
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["ADMIN_EMAILS_CC"];
            }
        }

        private static string ADMIN_EMAILS_BCC
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["ADMIN_EMAILS_BCC"];
            }
        }

        private static string ADMIN_EMAIL_SUBJECT
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["ADMIN_EMAIL_SUBJECT"];
            }
        }

        #endregion Properties

        #region Methods

        public static bool SendEmailNotification(string recipients, string body, bool isHtml)
        {
            bool returnValue = false;

            try
            {
                string sender = ADMIN_EMAIL_FROM;
                string cc = ADMIN_EMAILS_CC;
                string bcc = ADMIN_EMAILS_BCC;
                string subject = ADMIN_EMAIL_SUBJECT;

                using (MailMessage message = new MailMessage())
                {
                    message.From = new MailAddress(sender);
                    message.To.Add(recipients);

                    if (!string.IsNullOrWhiteSpace(cc))
                    {
                        message.CC.Add(cc);
                    }

                    if (!string.IsNullOrWhiteSpace(bcc))
                    {
                        message.Bcc.Add(bcc);
                    }

                    message.Subject = subject;
                    message.IsBodyHtml = isHtml;
                    message.Body = body;
                    message.Priority = MailPriority.Normal;

                    _client.Send(message);
                    returnValue = true;
                }
            }
            catch (Exception)
            {

            }

            return returnValue;
        }

        #endregion Methods
    }
}
